var a = require("../../requests/request.js"), t = getApp();

Page({
    data: {
        dealerInfoList: [],
        cityid: 0,
        cityname: "",
        carid: 0,
        img: "",
        carname: "",
        currentTab: 0,
        swiperTab: 0,
        carpriceimageurl: "",
        winHeight: 0,
        carparams: {},
        paramgroup: {},
        novaluegroup: {},
        dealerInfoListcount: !0
    },
    successCallback: function(a) {
        var t = this, e = a.Data;
        t.data.dealerInfoList = e.List;
        for (var i in t.data.dealerInfoList) {
            var r = "4S店" === t.data.dealerInfoList[i].DealerBizModeName;
            t.data.dealerInfoList[i].Is4S = r, void 0 != t.data.dealerInfoList[i].DealerBizModeName && t.data.dealerInfoList[i].DealerBizModeName.length > 2 && (t.data.dealerInfoList[i].DealerBizModeName = t.data.dealerInfoList[i].DealerBizModeName.substring(0, 2), 
            t.data.dealerInfoList[i].DealerTel = t.data.dealerInfoList[i].DealerTel.replace(/转/, ","), 
            t.data.dealerInfoList[i].DealerTelShow = t.data.dealerInfoList[i].DealerTel.split(",")[0]);
        }
        void 0 == t.data.dealerInfoList ? (t.data.dealerInfoListcount = !1, t.data.dealerInfoList = []) : t.data.dealerInfoListcount = !0, 
        t.setData({
            cityname: t.data.cityname,
            dealerInfoList: t.data.dealerInfoList,
            dealerInfoListcount: t.data.dealerInfoListcount
        });
    },
    getCarImagUrl: function() {
        var a = this, t = "http://image.bitauto.com/bt/price/priceChart/chart/" + this.data.carid + "/0_" + this.data.carid + "_600340.png";
        a.setData({
            carpriceimageurl: "http://image.bitauto.com/wap/a/2016/10/price_default.png"
        }), wx.request({
            url: "https://wxs.app.yiche.com/checkimage.ashx?url=" + t,
            success: function(e) {
                1 === e.data && a.setData({
                    carpriceimageurl: t
                });
            }
        });
    },
    setDealerData: function() {
        var t = this;
        a.getDealerInfoList(t.data.carid, t.data.cityid, function(a) {
            t.successCallback(a);
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        });
    },
    setParamDetail: function() {
        var t = this;
        a.getParamDetail(this.data.carid, function(a) {
            console.log(a);
            for (var e = new Map(), i = a.Data[0].ListStyleItem, r = 0; r < i.length; r++) if ("OutStat_BodyColor" == i[r].englishname) {
                var l = i[r].items[0].value;
                e.OutStat_BodyColor = JSON.parse(l);
            } else e[i[r].englishname] = i[r].items;
            t.setData({
                carparams: e
            }), t.setParamGroup();
        }, null, null);
    },
    setParamGroup: function() {
        var t = this, e = [];
        a.getParamOptions(function(a) {
            for (var i = 0; i < a.length; i++) {
                if (14 == a[i].GroupID) var r = !1;
                for (var l = 0; l < a[i].Fields.length; l++) {
                    var s = a[i].Fields[l].Key;
                    if ("" != s.trim() && t.data.carparams[s] && "" != t.data.carparams[s]) {
                        r = !0;
                        break;
                    }
                }
                r ? a[i].Exsit = !0 : (e.push(a[i].Name), a[i].Exsit = !1);
            }
            t.setData({
                paramgroup: a,
                novaluegroup: e
            });
        }, null, null);
    },
    onLoad: function(a) {
        var e = this;
        wx.getSystemInfo({
            success: function(a) {
                e.setData({
                    winHeight: a.windowHeight
                });
            }
        }), e.data.carid = a.carid, e.data.img = a.img, e.data.carname = a.showname + " " + a.carname, 
        e.data.cityid = t.globalData.locateCityInfo.id, e.data.cityname = t.globalData.locateCityInfo.name, 
        void 0 != t.globalData.selectCityParams.id && 0 != t.globalData.selectCityParams.id && "" != t.globalData.selectCityParams.id && (e.data.cityid = t.globalData.selectCityParams.id), 
        void 0 != t.globalData.selectCityParams.name && "" != t.globalData.selectCityParams.name && (e.data.cityname = t.globalData.selectCityParams.name), 
        e.getCarImagUrl(), e.setDealerData(), e.setParamDetail();
    },
    onShow: function() {
        var a = this;
        if (void 0 != t.globalData.selectCityParams.id && 0 != t.globalData.selectCityParams.id && "" != t.globalData.selectCityParams.id) {
            if (a.data.cityid === t.globalData.selectCityParams.id) return;
            a.data.cityid = t.globalData.selectCityParams.id;
        }
        void 0 != t.globalData.selectCityParams.name && "" != t.globalData.selectCityParams.name && (a.data.cityname = t.globalData.selectCityParams.name), 
        a.setDealerData();
    },
    onReady: function(a) {
        var t = this;
        wx.setNavigationBarTitle({
            title: t.data.carname
        });
    },
    onPullDownRefresh: function() {
        this.setDealerData(), this.getCarImagUrl(), this.setParamDetail(), wx.stopPullDownRefresh();
    },
    returnBtn: function() {
        t.gotoIndex();
    },
    gotoXunjia: function() {
        var a = this;
        wx.navigateTo({
            url: "../xunjia/xunjia?carid=" + a.data.carid + "&cityid=" + a.data.cityid + "&dealerid=0&img=" + a.data.img + "&carname=" + a.data.carname + "&subordertype=0"
        });
    }
});